home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tools / jade / lisp / find-autoloads.jl < prev    next >
Lisp/Scheme  |  1995-03-09  |  3KB  |  95 lines

  1. ;;;; find-autoloads.jl -- Rebuild the autoload.jl file
  2. ;;;  Copyright (C) 1994 John Harper <jsh@ukc.ac.uk>
  3.  
  4. ;;; This file is part of Jade.
  5.  
  6. ;;; Jade is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 2, or (at your option)
  9. ;;; any later version.
  10.  
  11. ;;; Jade is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;;; GNU General Public License for more details.
  15.  
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with Jade; see the file COPYING.  If not, write to
  18. ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. (provide 'find-autoloads)
  21.  
  22. ;;; Code to manipulate the sequence of autoload functions in autoload.jl
  23. ;;; Basically you just do `ESC x add-autoloads' to add all marked functions
  24. ;;; and macros to the list and `ESC x remove-autoloads' to take them out.
  25.  
  26. (defun autoload-insert-entry (str)
  27.   (if (find-next-string str (buffer-start))
  28.       (progn
  29.     (delete-area (match-start) (line-end (match-start)))
  30.     (goto-char (match-start)))
  31.     (unless (find-prev-regexp "^;;; ::autoload-end::" (buffer-end))
  32.       (error "autoload.jl file malformed"))
  33.     (goto-char (line-end (prev-line 1 (match-start))))
  34.     (insert "\n"))
  35.   (insert str))
  36.  
  37. (defun autoload-remove-entry (str)
  38.   (when (find-next-string str (buffer-start))
  39.     (goto-char (match-start))
  40.     (delete-area (match-start)
  41.          (line-start (next-line 1 (match-start))))))
  42.  
  43. (defun autoload-do-magic (buf line-fun)
  44.   (let
  45.       (aload-buf)
  46.     (when (setq aload-buf (open-file (file-name-concat lisp-lib-dir "autoload.jl")))
  47.       (goto-buffer aload-buf)
  48.       (let
  49.       ((pos (buffer-start))
  50.        form
  51.        (short-file-name (regexp-expand "^(.+)\\.jl$"
  52.                        (file-name-nondirectory
  53.                         (buffer-file-name buf))
  54.                        "\\1"))
  55.        (count 0))
  56.     (while (setq pos (find-next-regexp "^;;;###autoload" pos buf))
  57.       (setq form (regexp-expand-line "^;;;###autoload[\t ]*(.*)$" "\\1"
  58.                       pos buf))
  59.       (when (and form (not (equal "" form)))
  60.         (funcall line-fun form)
  61.         (setq count (1+ count))
  62.         (message form t))
  63.       (next-line 1 pos)
  64.       (when (and (regexp-match-line "^\\(def(macro|un) " pos buf)
  65.              (setq form (read (cons buf pos)))
  66.              (memq (car form) '(defun defmacro)))
  67.         (setq form (format nil (if (assq 'interactive form)
  68.                        ;; Can be called as a command
  69.                        "(autoload '%s %S t)"
  70.                      "(autoload '%s %S)")
  71.                    (nth 1 form)
  72.                    short-file-name))
  73.         (when (funcall line-fun form)
  74.           (setq count (1+ count))
  75.           (message form t))))
  76.     count))))
  77.  
  78. ;;;###autoload
  79. (defun add-autoloads (&optional buffer)
  80.   "Add all functions, macros or variables in the BUFFER marked by the magic
  81. rune `;;;###autoload' to the `autoload.jl' file."
  82.   (interactive)
  83.   (message (format nil "Found %d autoload definition(s)"
  84.            (autoload-do-magic (unless buffer (current-buffer))
  85.                       #'autoload-insert-entry))))
  86.  
  87. ;;;###autoload
  88. (defun remove-autoloads (&optional buffer)
  89.   "Removes all autoload definitions in the buffer BUFFER which are marked by
  90. the string `;;;###autoload' from the `autoload.jl' file."
  91.   (interactive)
  92.   (message (format nil "Removed %d autoload definition(s)"
  93.            (autoload-do-magic (unless buffer (current-buffer))
  94.                       #'autoload-remove-entry))))
  95.